<%@page import="com.hp.ccue.identity.util.WebRequestContextUtils"%>
<%@page
  import="com.hp.ccue.identity.authentication.domain.token.AccessTokenResponse"%>
<%@page
  import="com.hp.ccue.identity.authentication.domain.token.AccessTokenRequest"%>
<%@page import="com.hp.ccue.identity.IdmClient"%>
<%@page import="com.hp.ccue.identity.common.IdmConstant"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>User Details</title>
<style type="text/css">
body {
  width: 80%;
  height: 80%;
  position: absolute;
  margin-left: 50px;
  margin-top: 40px;
}

#contentDetail {
  width: 100%;
  height: 80%;
}
</style>
<script type="text/javascript">
  contentDetail
  function viewUsers() {
    var tenant = document.getElementById('tenant').value;
    window.frames["contentDetail"].src = "showUser.jsp?tenant=" + tenant;
  }
  function viewGroups() {
    var tenant = document.getElementById('tenant').value;
    window.frames["contentDetail"].src = "showGroup.jsp?tenant=" + tenant;
  }
  function viewRoles() {
    var tenant = document.getElementById('tenant').value;
    window.frames["contentDetail"].src = "showRole.jsp?tenant=" + tenant;
  }
</script>
</head>
<body>

  <%
      if (null != session.getAttribute(IdmConstant.IDM_X_AUTH_TOKEN)) {
          out.println("<h1>This is a secure page. Should be authenticated by IdM.</h1>");
      }
      Enumeration e = session.getAttributeNames();

      while (e.hasMoreElements()) {
          Object o = e.nextElement();
          out.print("<p>");
          out.print(o);
          out.print("</p>");
          out.print("-->");
          out.print(session.getAttribute(o.toString()));
          out.print("<br>");
      }

      /*
      if (WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentUser() == null) {
          AccessTokenRequest atrRequest = new AccessTokenRequest();
          atrRequest.setRequestToken((String) session.getAttribute(IdmConstant.IDM_X_AUTH_TOKEN));
          AccessTokenResponse atrResponse = WebRequestContextUtils.getIdmClient().getAuthenticationService()
                  .getAccessToken(atrRequest);
          session.setAttribute("accessToken", atrResponse);
      } else {
          session.getAttribute("accessToken");
      }
      */
  %>
<h2>
WebAppName: <%=request.getContextPath().substring(1) %>
</h2>
/<%=WebRequestContextUtils.getIdmClient() %>
  <a href="../index.jsp">Return</a>
  <%
      if (WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentUser() != null) {
  %>
    <br>
    <h3>View Users</h3>
    <table>
      <tr>
        <td>User:</td>
        <td colspan="2"><%=WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentUser().getName()%>/<%=WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentUser().getMetadata()%></td>
      </tr>
      <tr>
        <td>Tenant:</td>
        <td colspan="2"><input id="tenant" type=text
          value="<%=WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentTenant().getName()%>"></td>
      </tr>
      <tr>
        <td><input type="button" onclick="viewUsers()" value="viewUsers"></td>
        <td><input type="button" onclick="viewGroups()" value=viewGroups></td>
        <td><input type="button" onclick="viewRoles()" value=viewRoles></td>
      </tr>
    </table>
    <hr>
  <%
      }
  %>
  <iframe id="contentDetail"></iframe>

</body>
</html>